#!/bin/sh

trap 'rm -Rf ${DISTRIB}' EXIT

DISTRIB=../staff-mq_tmp$(printf %x $(date +%s))/
REVISION=$(LANG=en svn info --non-interactive 2>&- | grep 'Revision: ' | cut -d' ' -f2)
TARBALLNAME=../staff-mq-r${REVISION}.tar.bz2

test $(svn st --non-interactive | grep -vE '^\? ' | wc -l) -eq 0 || echo "\033[1mWARNING: working copy was locally modified\033[0m"

echo "creating tarball..."

#rm -Rf ${DISTRIB}
mkdir -p ${DISTRIB}staff-mq/
cp -Rf . ${DISTRIB}staff-mq/
cd ${DISTRIB}staff-mq/

find -type d -name .svn | xargs rm -Rf
make clean >/dev/null && make distclean >/dev/null
cd ..

tar c staff-mq | bzip2 >${TARBALLNAME}
rm -Rf ${DISTRIB}

echo "created ${TARBALLNAME}"
